﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;

namespace ProfilerPDS {
    
    
    
    public sealed class GraphicsProvider {
        
        private static readonly GraphicsProvider instance = new GraphicsProvider();

        Random rand = new Random(DateTime.Now.Millisecond);
        Dictionary<int, Color> _colors = new Dictionary<int, Color>();
        private int _colorIndex = 0;

        private GraphicsProvider() {
            init();
        }

        public static GraphicsProvider Instance {
            get {return instance;}
        }

        private void init() {
            initColors();
        }

        public void addVerticalLine(double X1,double Y1,double height,Canvas drawArea){
            Line verticalLine = new Line();
            verticalLine.X1 = X1;
            verticalLine.Y1 = Y1;
            verticalLine.X2 = X1;
            verticalLine.Y2 = height;
            verticalLine.StrokeDashArray.Insert(0, 5);
            verticalLine.StrokeDashArray.Insert(1,3);
            verticalLine.StrokeThickness = 1;
            verticalLine.Stroke = Brushes.Silver;
            drawArea.Children.Add(verticalLine);
        }

        private void initColors() {
            Color color;
            color = Color.FromRgb((byte)rand.Next(0, 255), (byte)rand.Next(0, 255), (byte)rand.Next(0, 255));
            _colors.Add(_colorIndex, color);        
        }

        internal Color getNextColor() {
            Color color;
            color=Color.FromRgb((byte)rand.Next(0, 255), (byte)rand.Next(0, 255), (byte)rand.Next(0, 255));
            _colorIndex++;                        
            _colors.Add(_colorIndex,color);
            return color;
        
        }

        internal Color getColor() {
          return _colors[_colorIndex];
        }


        
        internal Color getColor(int index) {
            return _colors[index];
        }
        
        internal void popColor() {
            _colorIndex--;
        }
    }
}
